/**
 * Created by gaoyj on 2018/7/3.
 */
$(function () {
    var $table = $("#dataTable");
    $table.bootstrapTable({
        //url:'/js/bootstrap_treegrid.json',
        url:"/queryNavigation",
        striped:true,
        sidePagenation:'server',
        idField:'id',
        clickToSelect: true,
        columns:[
            {
                field: 'ck',
                checkbox: true
            },{
                field:'name',
                title:'导航名称'
            },{
                field:'modifyTime',
                title:'修改时间',
                formatter: function (v, row, index) {
                    var modifyTime = v == null ? "-" : changeDateFormat(v)
                    return modifyTime;
                }
            }
        ],
        treeShowField: 'name',
        parentIdField: 'pid',
        onLoadSuccess: function(data) {
            $table.treegrid({
                initialState: 'collapsed',//收缩
                treeColumn: 1,//指明第几列数据改为树形
                expanderExpandedClass: 'glyphicon glyphicon-triangle-bottom',
                expanderCollapsedClass: 'glyphicon glyphicon-triangle-right',
                onChange: function() {
                    $table.bootstrapTable('resetWidth');
                }
            });
        }
    });
})
var ids = [];
function bingNav() {
    ids = [];
    var rows = $('#dataTable').bootstrapTable("getSelections");
    if (rows == null || rows.length === 0) {
        layer.msg("请选择要操作的数据");
        return;
    }
    for (var i = 0; i < rows.length; i++) {
        ids.push(rows[i].id);
    }
    $("#myModal").modal("show");
}
$("#bindBtn").click(function () {
    $.ajax({
        type: "post",
        url: "/bindDepartment",
        data: {
            ids:ids,
            department:$("#department").val(),
            JSESSIONID:sessionStorage.getItem('JSESSIONID')
        },
        dataType: "json",
        traditional: true,
        async: false,
        cache: false,
        success: function (data) {
            if (data.errorCode == 200) {
                $("#dataTable").bootstrapTable("refresh");
                layer.msg(data.errorMsg);
                $("#myModal").modal("hide");
            } else {
               layer.msg(data.errorMsg);
            }

        }
    });
})